Fix build breakage due to generalized type parameter and object bounds
authorBrian Koropoff <bkoropoff@gmail.com>
Fri, 29 Aug 2014 06:36:28 +0000 (23:36 -0700)
committerBrian Koropoff <bkoropoff@gmail.com>
Fri, 29 Aug 2014 08:30:15 +0000 (01:30 -0700)
It is worth noting that cargo was actually creating trait boxes
that contain non-static references, so I couldn't just put 'static
everywhere to appease rustc.

src/cargo/core/registry.rs
src/cargo/core/resolver.rs
src/cargo/core/shell.rs
src/cargo/core/source.rs
src/cargo/lib.rs
src/cargo/ops/cargo_compile.rs
src/cargo/ops/cargo_rustc/context.rs
src/cargo/sources/git/source.rs
src/cargo/util/config.rs

index 789bf149013d4bedac1b449847ed728b1954dbff..236f7e68c4076c9f24404e2536dc4cbb62b31b39 100644 (file)
@@ -16,7 +16,7 @@ impl Registry for Vec<Summary> {
 }
 
 pub struct PackageRegistry<'a> {
-    sources: SourceMap,
+    sources: SourceMap<'a>,
     overrides: Vec<SourceId>,
     config: &'a mut Config<'a>
 }
@@ -53,7 +53,7 @@ impl<'a> PackageRegistry<'a> {
         Ok(ret)
     }
 
-    pub fn move_sources(self) -> SourceMap {
+    pub fn move_sources(self) -> SourceMap<'a> {
         self.sources
     }
 
index 92d81d8dd25c371bd057ed4b1556f3163be938cc..3e5f6b90ce6df5fd7b7c195aeba4b3c4b674d079 100644 (file)
@@ -216,7 +216,7 @@ impl fmt::Show for Resolve {
     }
 }
 
-struct Context<'a, R> {
+struct Context<'a, R:'a> {
     registry: &'a mut R,
     resolve: Resolve,
 
index 5e93c0cb4163bd32676372ef6323f2efd2c54bbf..9c741e1ab1ff477191871531ae38f85a207f907e 100644 (file)
@@ -10,34 +10,34 @@ pub struct ShellConfig {
     pub tty: bool
 }
 
-enum AdequateTerminal {
-    NoColor(Box<Writer>),
-    Color(Box<Terminal<Box<Writer>>>)
+enum AdequateTerminal<'a> {
+    NoColor(Box<Writer+'a>),
+    Color(Box<Terminal<Box<Writer+'a>>+'a>)
 }
 
-pub struct Shell {
-    terminal: AdequateTerminal,
+pub struct Shell<'a> {
+    terminal: AdequateTerminal<'a>,
     config: ShellConfig
 }
 
-pub struct MultiShell {
-    out: Shell,
-    err: Shell,
+pub struct MultiShell<'a> {
+    out: Shell<'a>,
+    err: Shell<'a>,
     verbose: bool
 }
 
 pub type Callback<'a> = |&mut MultiShell|:'a -> IoResult<()>;
 
-impl MultiShell {
-    pub fn new(out: Shell, err: Shell, verbose: bool) -> MultiShell {
+impl<'a> MultiShell<'a> {
+    pub fn new(out: Shell<'a>, err: Shell<'a>, verbose: bool) -> MultiShell<'a> {
         MultiShell { out: out, err: err, verbose: verbose }
     }
 
-    pub fn out(&mut self) -> &mut Shell {
+    pub fn out(&mut self) -> &mut Shell<'a> {
         &mut self.out
     }
 
-    pub fn err(&mut self) -> &mut Shell {
+    pub fn err(&mut self) -> &mut Shell<'a> {
         &mut self.err
     }
 
@@ -72,17 +72,17 @@ impl MultiShell {
     }
 }
 
-pub type ShellCallback<'a> = |&mut Shell|:'a -> IoResult<()>;
+pub type ShellCallback<'a> = |&mut Shell<'a>|:'a -> IoResult<()>;
 
-impl Shell {
-    pub fn create(out: Box<Writer>, config: ShellConfig) -> Shell {
+impl<'a> Shell<'a> {
+    pub fn create(out: Box<Writer+'a>, config: ShellConfig) -> Shell<'a> {
         if config.tty && config.color {
-            let term: Option<term::TerminfoTerminal<Box<Writer>>> = Terminal::new(out);
+            let term: Option<term::TerminfoTerminal<Box<Writer+'a>>> = Terminal::new(out);
             term.map(|t| Shell {
-                terminal: Color(box t as Box<Terminal<Box<Writer>>>),
+                terminal: Color(box t as Box<Terminal<Box<Writer+'a>>>),
                 config: config
             }).unwrap_or_else(|| {
-                Shell { terminal: NoColor(box stderr() as Box<Writer>), config: config }
+                Shell { terminal: NoColor(box stderr() as Box<Writer+'a>), config: config }
             })
         } else {
             Shell { terminal: NoColor(out), config: config }
@@ -121,8 +121,8 @@ impl Shell {
     }
 }
 
-impl Terminal<Box<Writer>> for Shell {
-    fn new(out: Box<Writer>) -> Option<Shell> {
+impl<'a> Terminal<Box<Writer+'a>> for Shell<'a> {
+    fn new(out: Box<Writer+'a>) -> Option<Shell<'a>> {
         Some(Shell {
             terminal: NoColor(out),
             config: ShellConfig {
@@ -168,18 +168,18 @@ impl Terminal<Box<Writer>> for Shell {
         }
     }
 
-    fn unwrap(self) -> Box<Writer> {
+    fn unwrap(self) -> Box<Writer+'a> {
         fail!("Can't unwrap a Shell");
     }
 
-    fn get_ref<'a>(&'a self) -> &'a Box<Writer> {
+    fn get_ref<'b>(&'b self) -> &'b Box<Writer+'a> {
         match self.terminal {
             Color(ref c) => c.get_ref(),
             NoColor(ref w) => w
         }
     }
 
-    fn get_mut<'a>(&'a mut self) -> &'a mut Box<Writer> {
+    fn get_mut<'b>(&'b mut self) -> &'b mut Box<Writer+'a> {
         match self.terminal {
             Color(ref mut c) => c.get_mut(),
             NoColor(ref mut w) => w
@@ -187,7 +187,7 @@ impl Terminal<Box<Writer>> for Shell {
     }
 }
 
-impl Writer for Shell {
+impl<'a> Writer for Shell<'a> {
     fn write(&mut self, buf: &[u8]) -> IoResult<()> {
         match self.terminal {
             Color(ref mut c) => c.write(buf),
index 7c1b2f11f0269236a21070050d7e59b858c80233..1a92b6052d01ba8f096411eea71f671e410b710c 100644 (file)
@@ -244,10 +244,10 @@ impl SourceId {
         }
     }
 
-    pub fn load(&self, config: &mut Config) -> Box<Source> {
+    pub fn load<'a>(&self, config: &'a mut Config) -> Box<Source+'a> {
         log!(5, "loading SourceId; {}", self);
         match self.kind {
-            GitKind(..) => box GitSource::new(self, config) as Box<Source>,
+            GitKind(..) => box GitSource::new(self, config) as Box<Source+'a>,
             PathKind => {
                 let path = match self.url.to_file_path() {
                     Ok(p) => p,
@@ -255,7 +255,7 @@ impl SourceId {
                 };
                 box PathSource::new(&path, self) as Box<Source>
             },
-            RegistryKind => box DummyRegistrySource::new(self) as Box<Source>,
+            RegistryKind => box DummyRegistrySource::new(self) as Box<Source+'a>,
         }
     }
 
@@ -267,17 +267,17 @@ impl SourceId {
     }
 }
 
-pub struct SourceMap {
-    map: HashMap<SourceId, Box<Source>>
+pub struct SourceMap<'a> {
+    map: HashMap<SourceId, Box<Source+'a>>
 }
 
-pub type Sources<'a> = Values<'a, SourceId, Box<Source>>;
-pub type SourcesMut<'a> = iter::Map<'static, (&'a SourceId, &'a mut Box<Source>),
-                                    &'a mut Source,
-                                    MutEntries<'a, SourceId, Box<Source>>>;
+pub type Sources<'a> = Values<'a, SourceId, Box<Source+'a>>;
+pub type SourcesMut<'a> = iter::Map<'static, (&'a SourceId, &'a mut Box<Source+'a>),
+                                    &'a mut Source+'a,
+                                    MutEntries<'a, SourceId, Box<Source+'a>>>;
 
-impl SourceMap {
-    pub fn new() -> SourceMap {
+impl<'a> SourceMap<'a> {
+    pub fn new() -> SourceMap<'a> {
         SourceMap {
             map: HashMap::new()
         }
@@ -287,27 +287,27 @@ impl SourceMap {
         self.map.contains_key(id)
     }
 
-    pub fn get(&self, id: &SourceId) -> Option<&Source> {
+    pub fn get(&self, id: &SourceId) -> Option<&Source+'a> {
         let source = self.map.find(id);
 
         source.map(|s| {
-            let s: &Source = *s;
+            let s: &Source+'a = *s;
             s
         })
     }
 
-    pub fn get_mut(&mut self, id: &SourceId) -> Option<&mut Source> {
+    pub fn get_mut(&mut self, id: &SourceId) -> Option<&mut Source+'a> {
         self.map.find_mut(id).map(|s| {
-            let s: &mut Source = *s;
+            let s: &mut Source+'a = *s;
             s
         })
     }
 
-    pub fn get_by_package_id(&self, pkg_id: &PackageId) -> Option<&Source> {
+    pub fn get_by_package_id(&self, pkg_id: &PackageId) -> Option<&Source+'a> {
         self.get(pkg_id.get_source_id())
     }
 
-    pub fn insert(&mut self, id: &SourceId, source: Box<Source>) {
+    pub fn insert(&mut self, id: &SourceId, source: Box<Source+'a>) {
         self.map.insert(id.clone(), source);
     }
 
@@ -315,26 +315,26 @@ impl SourceMap {
         self.map.len()
     }
 
-    pub fn sources(&self) -> Sources {
+    pub fn sources(&'a self) -> Sources<'a> {
         self.map.values()
     }
 
-    pub fn sources_mut(&mut self) -> SourcesMut {
-        self.map.mut_iter().map(|(_, v)| { let s: &mut Source = *v; s })
+    pub fn sources_mut(&'a mut self) -> SourcesMut<'a> {
+        self.map.mut_iter().map(|(_, v)| { let s: &mut Source+'a = *v; s })
     }
 }
 
-pub struct SourceSet {
-    sources: Vec<Box<Source>>
+pub struct SourceSet<'a> {
+    sources: Vec<Box<Source+'a>>
 }
 
-impl SourceSet {
-    pub fn new(sources: Vec<Box<Source>>) -> SourceSet {
+impl<'a> SourceSet<'a> {
+    pub fn new(sources: Vec<Box<Source+'a>>) -> SourceSet<'a> {
         SourceSet { sources: sources }
     }
 }
 
-impl Registry for SourceSet {
+impl<'a> Registry for SourceSet<'a> {
     fn query(&mut self, name: &Dependency) -> CargoResult<Vec<Summary>> {
         let mut ret = Vec::new();
 
@@ -346,7 +346,7 @@ impl Registry for SourceSet {
     }
 }
 
-impl Source for SourceSet {
+impl<'a> Source for SourceSet<'a> {
     fn update(&mut self) -> CargoResult<()> {
         for source in self.sources.mut_iter() {
             try!(source.update());
index 8144eb39666a24dd5b364f5138b055558d8822e8..f01277bb4bfc3d2210ea13c67957e8bc11b6be62 100644 (file)
@@ -150,7 +150,7 @@ pub fn process_executed<'a,
     }
 }
 
-pub fn shell(verbose: bool) -> MultiShell {
+pub fn shell(verbose: bool) -> MultiShell<'static> {
     let tty = stderr_raw().isatty();
     let stderr = box stderr() as Box<Writer>;
 
index 8b686af2d75badee6ce07f0d8e72dc6081c32f3b..23b0cf12f889e2d3a219ea0809ea6461a3ea533f 100644 (file)
@@ -36,7 +36,7 @@ use util::{CargoResult, Wrap, config, internal, human, ChainError, profile};
 pub struct CompileOptions<'a> {
     pub update: bool,
     pub env: &'a str,
-    pub shell: &'a mut MultiShell,
+    pub shell: &'a mut MultiShell<'a>,
     pub jobs: Option<uint>,
     pub target: Option<&'a str>,
     pub dev_deps: bool,
index cfa62bdc24327288e34e43231f190a4b696b613f..6ee234b2a9b36b2a8ce5cf4cb2b0713cd888e132 100644 (file)
@@ -19,7 +19,7 @@ pub struct Context<'a, 'b> {
     pub rustc_version: String,
     pub config: &'b mut Config<'b>,
     pub resolve: &'a Resolve,
-    pub sources: &'a SourceMap,
+    pub sources: &'a SourceMap<'b>,
     pub compilation: Compilation,
 
     env: &'a str,
index b0198dd950aff79638575d29e707c8c13726a111..c3d80132f5864ec3cf772fbf985ff00b1cc57502 100644 (file)
@@ -12,7 +12,7 @@ use sources::git::utils::{GitReference, GitRemote, Master, Other, GitRevision};
 
 /* TODO: Refactor GitSource to delegate to a PathSource
  */
-pub struct GitSource<'a, 'b> {
+pub struct GitSource<'a, 'b:'a> {
     remote: GitRemote,
     reference: GitReference,
     db_path: Path,
index 6e03115ac6bc01496f0c2cd48614742aed28d680..01e54438370293209c8731fe88626d48e194984a 100644 (file)
@@ -9,7 +9,7 @@ use util::toml as cargo_toml;
 
 pub struct Config<'a> {
     home_path: Path,
-    shell: &'a mut MultiShell,
+    shell: &'a mut MultiShell<'a>,
     jobs: uint,
     target: Option<String>,
     linker: Option<String>,